﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Text;

using ZhimeiSoft.Framework.Server.Base;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Server.DAL.Interface;

namespace ZhimeiSoft.CharmManager.Server.DAL
{
    public class ServiceItemCategoryDAL : BaseDal, IServiceItemCategoryDAL
    {
        #region IServiceItemCategoryDAL 成员
        /// <summary>
        /// 设置SQL语句中的参数
        /// </summary>
        /// <param name="cmd">DbCommand对象</param>
        /// <param name="customer">客户实体类</param>
        private void AddInSqlParameters(ref DbCommand cmd, DBEntityServiceItemCategory category)
        {
            if (category == null || cmd == null)
                return;

            DB.AddInParameter(cmd, DBEntityServiceItemCategory.FieldName.SNAME, DbType.String, category.SNAME);
            DB.AddInParameter(cmd, DBEntityServiceItemCategory.FieldName.SPARENTCATEGORYID, DbType.Int32, category.SPARENTCATEGORYID);
        }

        public void InsertServiceItemCategory(DBEntityServiceItemCategory category)
        {
            string strSQL = ServiceItemCategoryDAL_Const.SQL_INSERT_SERVICEITEMCATEGORY;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            AddInSqlParameters(ref cmd, category);
            DB.ExecuteNonQuery(cmd);
        }

        public void UpdateServiceItemCategory(DBEntityServiceItemCategory category)
        {
            string strSQL = ServiceItemCategoryDAL_Const.SQL_UPDATE_SERVICEITEMCATEGORY;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityServiceItemCategory.FieldName.SCATEGORYID, DbType.Int32, category.SCATEGORYID);
            AddInSqlParameters(ref cmd, category);
            DB.ExecuteNonQuery(cmd);
        }

        public void DeleteServiceItemCategory(int categoryid)
        {
            string strSQL = ServiceItemCategoryDAL_Const.SQL_DELETE_SERVICEITEMCATEGORY;
            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            DB.AddInParameter(cmd, DBEntityServiceItemCategory.FieldName.SCATEGORYID, DbType.Int32, categoryid);
            DB.ExecuteNonQuery(cmd);
        }

        public DataSet QueryServiceItemCategory(string sFilter)
        {
            string strSQL = ServiceItemCategoryDAL_Const.SQL_SELECT_SERVICEITEMCATEGORY;
            if (sFilter.Trim() != string.Empty)
                strSQL += " WHERE " + sFilter;

            DbCommand cmd = DB.GetSqlStringCommand(strSQL);
            return DB.ExecuteDataSet(cmd);
        }

        #endregion
    }
}
